(deftemplate questionList 
          (multislot question)
)
(deftemplate disp
          (slot out)
)
(deftemplate answer
          (slot in)
)

(deffacts factslist
(start)
(questionList (question 01 "Is it cloudy outside?"))
(questionList (question 02 "Is it sunny outside?"))
(questionList (question 10 "Is it Cold outside?" "It will Rain."))
(questionList (question 11 "Is Hot outside?" "There will be nice weather."))
)
;;;;;;;;;;;;;;;;;;;;;;;1
(defrule q01q
	
	?d <- (start)
	(questionList (question 01 ?x $?))
=>
	(assert (q01))
	(assert (disp(out ?x)))
	(retract ?d)
)

(defrule q01t
	?a <- (disp(out ?))
	?b <- (answer(in T))
	?c <- (q01)
=>
	(assert(q01 T))
	(assert (q10q))
	(retract ?a ?b ?c)
)

(defrule q01f
	?a <- (disp(out ?))
	?b <- (answer(in F))
	?c <- (q01)
=>
	(assert(q01 F))
	(assert (q02q))
	(retract ?a ?b ?c)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;02
(defrule q02q
	?d <- (q02q)
	(questionList (question 02 ?x $?))
=>
	(assert (q02))
	(assert (disp(out ?x)))
	(retract ?d)
)

(defrule q02t
	?a <- (disp(out ?))
	?b <- (answer(in T))
	?c <- (q02)
=>
	(assert(q02 T))
	(assert (q11q))
	(retract ?a ?b ?c)
)

(defrule q02f
	?a <- (disp(out ?))
	?b <- (answer(in F))
	?c <- (q02)
=>
	(assert(q02 F))
	(assert (q03q))
	(retract ?a ?b ?c)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;10
(defrule q10q
	?d <- (q10q)
	(questionList (question 10 ?x $?))
=>
	(assert (q10))
	(assert (disp(out ?x)))
	(retract ?d)
)

(defrule q10t
	(disp(out ?))
	(answer(in T))
	(q10)
	?d <- (questionList (question 10 ? ?y))	
=>
	(retract *)
	(assert (finished ?y))
)

(defrule q10f
	?a <- (disp(out ?))
	?b <- (answer(in F))
	?c <- (q10)
=>
	(assert(q10 F))
	(assert (failcat))
	(retract ?a ?b ?c)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;11
(defrule q11q
	?d <- (q11q)
	(questionList (question 11 ?x $?))
=>
	(assert (q11))
	(assert (disp(out ?x)))
	(retract ?d)
)

(defrule q11t
	(disp(out ?))
	(answer(in T))
	(q11)
	?d <- (questionList (question 11 ? ?y))	
=>
	(retract *)
	(assert (finished ?y))
)

(defrule q11f
	?a <- (disp(out ?))
	?b <- (answer(in F))
	?c <- (q11)
=>
	(assert(q11 F))
	(assert (failcat))
	(retract ?a ?b ?c)
)
(defrule failcat
	?a <- (failcat)
=>
	(retract *)
	(assert (finished "Your problem does not seem to fit into any of the categories known by this system, please consult a professional or retry this tool again")) 
)
